prev_sens<-0
prev_oneMSpec<-0
sorted_sens<-order(oneMSpecArr)
i1<-1
while(i1<=nsens) 
{
Sens=SensArr[sorted_sens[i1]]
oneMSpec=oneMSpecArr[sorted_sens[i1]]
dx<-oneMSpec-prev_oneMSpec
y<-(Sens+prev_sens)/2
AUC<-AUC+y*dx
#print(c("Y",y,"dx",dx))
prev_oneMSpec<-oneMSpec
prev_sens<-Sens
i1<-i1+1
}
print(c("AUC",AUC))
wr1<-matrix(nrow=1, ncol=length(wanted_ranks))
colnames(wr1)<-colnames(geno1)
rownames(wr1)<-rownames(geno1)
wr1[1,]<-wanted_ranks
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","RANK")
        #surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
#AUC<-surv$concordance
#Hugues code start
dt1<-dt[sort.list(dt[,"OS"]), ]
i1<-1
hazard_rank<-dt1[,11]
N<-nrow(dt1)
survival_time<-dt1[,"OS"]
k<-0
SensArr<-c()
oneMSpecArr<-c()
nsens<-1
SensArr[nsens]<-0
oneMSpecArr[nsens]<-0
nsens<-nsens+1
while(i1<nrow(dt1)+1)
{
print(paste(i1,nsens))
#if(k != dt1[i1,11])
#{
#pi<-i
t<-dt1[i1,"OS"]
#coln<-colnames(geno)
c<-hazard_rank[i1]
Count_M_ge_c <-length(which(hazard_rank>=c))
Pr_M_ge_c<-Count_M_ge_c/N
Count_T_le_t<-length(which(survival_time<=t))
Pr_T_le_t<-Count_T_le_t/N
Count_T_le_t_given_M_ge_c<-length(which(survival_time<=t & hazard_rank>=c))
Count_T_gt_t_given_M_lt_c<-length(which(survival_time>t & hazard_rank<c))
Pr_T_gt_t_given_M_lt_c<-Count_T_gt_t_given_M_lt_c/(N-Count_M_ge_c)
Sens<- (Count_T_le_t_given_M_ge_c)/Count_T_le_t
if((N==Count_T_le_t) {
Spec<-0
} else {
        Spec<-Count_T_gt_t_given_M_lt_c/(N-Count_T_le_t)
}
oneMSpec<-1-Spec
SensArr[nsens]<-Sens
oneMSpecArr[nsens]<-oneMSpec
nsens<- nsens+1
#print(c("Y",y,"dx",dx))
k<-dt1[i1,11]
#}
i1<-i1+1
}
SensArr[nsens]<-1
oneMSpecArr[nsens]<-1
AUC<-0
prev_sens<-0
prev_oneMSpec<-0
sorted_sens<-order(oneMSpecArr)
i1<-1
while(i1<=nsens) 
{
Sens=SensArr[sorted_sens[i1]]
oneMSpec=oneMSpecArr[sorted_sens[i1]]
dx<-oneMSpec-prev_oneMSpec
y<-(Sens+prev_sens)/2
AUC<-AUC+y*dx
#print(c("Y",y,"dx",dx))
prev_oneMSpec<-oneMSpec
prev_sens<-Sens
i1<-i1+1
}
print(c("AUC",AUC))#pi<-i
t<-dt1[i1,"OS"]
#coln<-colnames(geno)
c<-hazard_rank[i1]
Count_M_ge_c <-length(which(hazard_rank>=c))
Pr_M_ge_c<-Count_M_ge_c/N
Count_T_le_t<-length(which(survival_time<=t))
Pr_T_le_t<-Count_T_le_t/N
Count_T_le_t_given_M_ge_c<-length(which(survival_time<=t & hazard_rank>=c))
Count_T_gt_t_given_M_lt_c<-length(which(survival_time>t & hazard_rank<c))
Pr_T_gt_t_given_M_lt_c<-Count_T_gt_t_given_M_lt_c/(N-Count_M_ge_c)
Sens<- (Count_T_le_t_given_M_ge_c)/Count_T_le_t
if(N==Count_T_le_t) {
Spec<-0
} else {
        Spec<-Count_T_gt_t_given_M_lt_c/(N-Count_T_le_t)
}
oneMSpec<-1-Spec
SensArr[nsens]<-Sens
oneMSpecArr[nsens]<-oneMSpec
nsens<- nsens+1
#print(c("Y",y,"dx",dx))
k<-dt1[i1,11]
wr1<-matrix(nrow=1, ncol=length(wanted_ranks))
colnames(wr1)<-colnames(geno1)
rownames(wr1)<-rownames(geno1)
wr1[1,]<-wanted_ranks
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","RANK")
        #surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
#AUC<-surv$concordance
#Hugues code start
dt1<-dt[sort.list(dt[,"OS"]), ]
i1<-1
hazard_rank<-dt1[,11]
N<-nrow(dt1)
survival_time<-dt1[,"OS"]
k<-0
SensArr<-c()
oneMSpecArr<-c()
nsens<-1
SensArr[nsens]<-0
oneMSpecArr[nsens]<-0
nsens<-nsens+1
while(i1<nrow(dt1)+1)
{
print(paste(i1,nsens))
#if(k != dt1[i1,11])
#{
#pi<-i
t<-dt1[i1,"OS"]
#coln<-colnames(geno)
c<-hazard_rank[i1]
Count_M_ge_c <-length(which(hazard_rank>=c))
Pr_M_ge_c<-Count_M_ge_c/N
Count_T_le_t<-length(which(survival_time<=t))
Pr_T_le_t<-Count_T_le_t/N
Count_T_le_t_given_M_ge_c<-length(which(survival_time<=t & hazard_rank>=c))
Count_T_gt_t_given_M_lt_c<-length(which(survival_time>t & hazard_rank<c))
Pr_T_gt_t_given_M_lt_c<-Count_T_gt_t_given_M_lt_c/(N-Count_M_ge_c)
Sens<- (Count_T_le_t_given_M_ge_c)/Count_T_le_t
if(N==Count_T_le_t) {
Spec<-0
} else {
        Spec<-Count_T_gt_t_given_M_lt_c/(N-Count_T_le_t)
}
oneMSpec<-1-Spec
SensArr[nsens]<-Sens
oneMSpecArr[nsens]<-oneMSpec
nsens<- nsens+1
#print(c("Y",y,"dx",dx))
k<-dt1[i1,11]
#}
i1<-i1+1
}
SensArr[nsens]<-1
oneMSpecArr[nsens]<-1
AUC<-0
prev_sens<-0
prev_oneMSpec<-0
sorted_sens<-order(oneMSpecArr)
i1<-1
while(i1<=nsens) 
{
Sens=SensArr[sorted_sens[i1]]
oneMSpec=oneMSpecArr[sorted_sens[i1]]
dx<-oneMSpec-prev_oneMSpec
y<-(Sens+prev_sens)/2
AUC<-AUC+y*dx
#print(c("Y",y,"dx",dx))
prev_oneMSpec<-oneMSpec
prev_sens<-Sens
i1<-i1+1
}
print(c("AUC",AUC))
plot(oneMSpecArr,SensArr)
plot(sort(oneMSpecArr),sort(SensArr))
sorted_sens<-order(oneMSpecArr)
plot(oneMSpecArr[sorted_sens],SensArr[sorted_sens])
sorted_sens<-order(SensArr)
plot(oneMSpecArr[sorted_sens],SensArr[sorted_sens])
plot(oneMSpecArr[sorted_sens],SensArr[sorted_sens])
plot(oneMSpecArr[sorted_sens],SensArr[sorted_sens])
plot(oneMSpecArr[sorted_sens],SensArr[sorted_sens])
plot(sort(oneMSpecArr),sort(SensArr))
AUC<-0
prev_sens<-0
prev_oneMSpec<-0
sorted_spec<-order(oneMSpecArr)
sorted_sens<-order(SensArr)
i1<-1
while(i1<=nsens) 
{
Sens=SensArr[sorted_sens[i1]]
oneMSpec=oneMSpecArr[sorted_spec[i1]]
dx<-oneMSpec-prev_oneMSpec
y<-(Sens+prev_sens)/2
AUC<-AUC+y*dx
#print(c("Y",y,"dx",dx))
prev_oneMSpec<-oneMSpec
prev_sens<-Sens
i1<-i1+1
}
print(c("AUC",AUC))
time_order <-order(survival_time)
time_order[1:10]
time_order[10:110]
dt1$OS[1:10]
wr1<-matrix(nrow=1, ncol=length(wanted_ranks))
colnames(wr1)<-colnames(geno1)
rownames(wr1)<-rownames(geno1)
wr1[1,]<-wanted_ranks
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","RANK")
        #surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
#AUC<-surv$concordance
#Hugues code start
dt1<-dt[sort.list(dt[,"OS"]), ]
i1<-1
hazard_rank<-dt1[,11]
N<-nrow(dt1)
survival_time<-dt1[,"OS"]
k<-0
SensArr<-c()
oneMSpecArr<-c()
nsens<-1
SensArr[nsens]<-0
oneMSpecArr[nsens]<-0
nsens<-nsens+1
hazard_order <-order(hazard_rank)
while(i1<nrow(dt1)+1)
{
print(paste(i1,nsens))
#if(k != dt1[i1,11])
#{
#pi<-i
#t<-dt1[i1,"OS"]
#coln<-colnames(geno)
#c<-hazard_rank[i1]
t<-dt1[hazard_order[i1]]
c<-hazard_rank[[hazard_order[i1]]
Count_M_ge_c <-length(which(hazard_rank>=c))
Pr_M_ge_c<-Count_M_ge_c/N
Count_T_le_t<-length(which(survival_time<=t))
Pr_T_le_t<-Count_T_le_t/N
Count_T_le_t_given_M_ge_c<-length(which(survival_time<=t & hazard_rank>=c))
Count_T_gt_t_given_M_lt_c<-length(which(survival_time>t & hazard_rank<c))
Pr_T_gt_t_given_M_lt_c<-Count_T_gt_t_given_M_lt_c/(N-Count_M_ge_c)
#print(Pr_T_gt_t_given_M_lt_c)
Sens<- (Count_T_le_t_given_M_ge_c)/Count_T_le_t
if(N==Count_T_le_t) {
Spec<-0
} else {
        Spec<-Count_T_gt_t_given_M_lt_c/(N-Count_T_le_t)
}
oneMSpec<-1-Spec
SensArr[nsens]<-Sens
oneMSpecArr[nsens]<-oneMSpec
nsens<- nsens+1
#print(c("Y",y,"dx",dx))
k<-dt1[i1,11]
#}
i1<-i1+1
}
SensArr[nsens]<-1
oneMSpecArr[nsens]<-1
AUC<-0
prev_sens<-0
prev_oneMSpec<-0
sorted_spec<-order(oneMSpecArr)
sorted_sens<-order(SensArr)
i1<-1
while(i1<=nsens) 
{
Sens=SensArr[sorted_sens[i1]]
oneMSpec=oneMSpecArr[sorted_spec[i1]]
dx<-oneMSpec-prev_oneMSpec
y<-(Sens+prev_sens)/2
AUC<-AUC+y*dx
#print(c("Y",y,"dx",dx))
prev_oneMSpec<-oneMSpec
prev_sens<-Sens
i1<-i1+1
}
print(c("AUC",AUC))
wr1<-matrix(nrow=1, ncol=length(wanted_ranks))
colnames(wr1)<-colnames(geno1)
rownames(wr1)<-rownames(geno1)
wr1[1,]<-wanted_ranks
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","RANK")
        #surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
#AUC<-surv$concordance
#Hugues code start
dt1<-dt[sort.list(dt[,"OS"]), ]
i1<-1
hazard_rank<-dt1[,11]
N<-nrow(dt1)
survival_time<-dt1[,"OS"]
k<-0
SensArr<-c()
oneMSpecArr<-c()
nsens<-1
SensArr[nsens]<-0
oneMSpecArr[nsens]<-0
nsens<-nsens+1
hazard_order <-order(hazard_rank)
while(i1<nrow(dt1)+1)
{
print(paste(i1,nsens))
#if(k != dt1[i1,11])
#{
#pi<-i
#t<-dt1[i1,"OS"]
#coln<-colnames(geno)
#c<-hazard_rank[i1]
t<-dt1[hazard_order[i1],"OS"]
c<-hazard_rank[[hazard_order[i1]]
Count_M_ge_c <-length(which(hazard_rank>=c))
Pr_M_ge_c<-Count_M_ge_c/N
Count_T_le_t<-length(which(survival_time<=t))
Pr_T_le_t<-Count_T_le_t/N
Count_T_le_t_given_M_ge_c<-length(which(survival_time<=t & hazard_rank>=c))
Count_T_gt_t_given_M_lt_c<-length(which(survival_time>t & hazard_rank<c))
Pr_T_gt_t_given_M_lt_c<-Count_T_gt_t_given_M_lt_c/(N-Count_M_ge_c)
#print(Pr_T_gt_t_given_M_lt_c)
Sens<- (Count_T_le_t_given_M_ge_c)/Count_T_le_t
if(N==Count_T_le_t) {
Spec<-0
} else {
        Spec<-Count_T_gt_t_given_M_lt_c/(N-Count_T_le_t)
}
oneMSpec<-1-Spec
SensArr[nsens]<-Sens
oneMSpecArr[nsens]<-oneMSpec
nsens<- nsens+1
#print(c("Y",y,"dx",dx))
k<-dt1[i1,11]
#}
i1<-i1+1
}
SensArr[nsens]<-1
oneMSpecArr[nsens]<-1
AUC<-0
prev_sens<-0
prev_oneMSpec<-0
sorted_spec<-order(oneMSpecArr)
sorted_sens<-order(SensArr)
i1<-1
while(i1<=nsens) 
{
Sens=SensArr[sorted_sens[i1]]
oneMSpec=oneMSpecArr[sorted_spec[i1]]
dx<-oneMSpec-prev_oneMSpec
y<-(Sens+prev_sens)/2
AUC<-AUC+y*dx
#print(c("Y",y,"dx",dx))
prev_oneMSpec<-oneMSpec
prev_sens<-Sens
i1<-i1+1
}
print(c("AUC",AUC))
wr1<-matrix(nrow=1, ncol=length(wanted_ranks))
colnames(wr1)<-colnames(geno1)
rownames(wr1)<-rownames(geno1)
wr1[1,]<-wanted_ranks
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","RANK")
        #surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
#AUC<-surv$concordance
#Hugues code start
dt1<-dt[sort.list(dt[,"OS"]), ]
i1<-1
hazard_rank<-dt1[,11]
N<-nrow(dt1)
survival_time<-dt1[,"OS"]
k<-0
SensArr<-c()
oneMSpecArr<-c()
nsens<-1
SensArr[nsens]<-0
oneMSpecArr[nsens]<-0
nsens<-nsens+1
hazard_order <-order(hazard_rank)
while(i1<nrow(dt1)+1)
{
print(paste(i1,nsens))
#if(k != dt1[i1,11])
#{
#pi<-i
#t<-dt1[i1,"OS"]
#coln<-colnames(geno)
#c<-hazard_rank[i1]
t<-dt1[hazard_order[i1],"OS"]
c<-hazard_rank[hazard_order[i1]]
Count_M_ge_c <-length(which(hazard_rank>=c))
Pr_M_ge_c<-Count_M_ge_c/N
Count_T_le_t<-length(which(survival_time<=t))
Pr_T_le_t<-Count_T_le_t/N
Count_T_le_t_given_M_ge_c<-length(which(survival_time<=t & hazard_rank>=c))
Count_T_gt_t_given_M_lt_c<-length(which(survival_time>t & hazard_rank<c))
Pr_T_gt_t_given_M_lt_c<-Count_T_gt_t_given_M_lt_c/(N-Count_M_ge_c)
#print(Pr_T_gt_t_given_M_lt_c)
Sens<- (Count_T_le_t_given_M_ge_c)/Count_T_le_t
if(N==Count_T_le_t) {
Spec<-0
} else {
        Spec<-Count_T_gt_t_given_M_lt_c/(N-Count_T_le_t)
}
oneMSpec<-1-Spec
SensArr[nsens]<-Sens
oneMSpecArr[nsens]<-oneMSpec
nsens<- nsens+1
#print(c("Y",y,"dx",dx))
k<-dt1[i1,11]
#}
i1<-i1+1
}
SensArr[nsens]<-1
oneMSpecArr[nsens]<-1
AUC<-0
prev_sens<-0
prev_oneMSpec<-0
sorted_spec<-order(oneMSpecArr)
sorted_sens<-order(SensArr)
i1<-1
while(i1<=nsens) 
{
Sens=SensArr[sorted_sens[i1]]
oneMSpec=oneMSpecArr[sorted_spec[i1]]
dx<-oneMSpec-prev_oneMSpec
y<-(Sens+prev_sens)/2
AUC<-AUC+y*dx
#print(c("Y",y,"dx",dx))
prev_oneMSpec<-oneMSpec
prev_sens<-Sens
i1<-i1+1
}
print(c("AUC",AUC))
plot(oneMSpecArr,SensArr)
plot(oneMSpecArr[sorted_spec],SensArr[sorted_sens])
library(survivalROC)
utils:::menuInstallPkgs()
library(survivalROC)
sur<-survivalROC(dt1$OS,dt1$"ALIVEOS",hazard_rank,predict.time=24)
sur<-survivalROC(dt1$OS,dt1$"ALIVEOS",hazard_rank,predict.time=24,span=2)
sur
plot(sur$FP,sur$TP)
plot(oneMSpecArr[sorted_spec],SensArr[sorted_sens])
sur<-survivalROC(dt1$OS,dt1$"ALIVEOS",hazard_rank,predict.time=12,span=2)
plot(oneMSpecArr[sorted_spec],SensArr[sorted_sens])
plot(sur$FP,sur$TP)
sur$AUC
sur<-survivalROC(dt1$OS,dt1$"ALIVEOS",hazard_rank,predict.time=median(dt1$OS),span=2)
sur$AUC
median(dt1$OS)
plot(oneMSpecArr,SensArr)
sur<-survivalROC(dt1$OS,dt1$"ALIVEOS",hazard_rank,predict.time=median(dt1$OS),span=1)
plot(sur$FP,sur$TP)
sur$AUC
AUC
SensArr[nsens]<-1
oneMSpecArr[nsens]<-1
AUC<-0
prev_sens<-0
prev_oneMSpec<-0
sorted_spec<-order(oneMSpecArr)
sorted_sens<-order(SensArr)
i1<-1
while(i1<=nsens) 
{
Sens=SensArr[i1]
oneMSpec=oneMSpecArr[i1]
dx<-oneMSpec-prev_oneMSpec
y<-(Sens+prev_sens)/2
AUC<-AUC+y*dx
#print(c("Y",y,"dx",dx))
prev_oneMSpec<-oneMSpec
prev_sens<-Sens
i1<-i1+1
}
print(c("AUC",AUC))
SensArr[nsens]<-1
oneMSpecArr[nsens]<-1
AUC<-0
prev_sens<-0
prev_oneMSpec<-0
sorted_spec<-order(oneMSpecArr)
sorted_sens<-order(SensArr)
i1<-1
while(i1<=nsens) 
{
Sens=SensArr[sorted_spec[i1]]
oneMSpec=oneMSpecArr[sorted_spec[i1]]
dx<-oneMSpec-prev_oneMSpec
y<-(Sens+prev_sens)/2
AUC<-AUC+y*dx
#print(c("Y",y,"dx",dx))
prev_oneMSpec<-oneMSpec
prev_sens<-Sens
i1<-i1+1
}
print(c("AUC",AUC))
savehistory("k.R")
